package com.three.DAO.impl;

import com.three.DAO.BaseDAO;
import com.three.DAO.ServicePackageDAO;
import com.three.entity.NetPackage;
import com.three.entity.ServicePackage;
import com.three.entity.SuperPackage;
import com.three.entity.TalkPackage;

import java.sql.ResultSet;
import java.sql.SQLException;

public class ServicePackageDAOImpl extends BaseDAO implements ServicePackageDAO {
    ResultSet rs=null;
    @Override
    public ServicePackage selectPackage(int id) {
        String sql="select packagename,talktime,smscount,flow,price from package where id=?";
        ServicePackage servicePackage=null;
        Object[] values={id};
        rs=super.exeQuery(sql,values);
        try{
            while(rs.next()){
                if(id==1){
                    servicePackage=new TalkPackage(id,rs.getString("packagename"),rs.getInt("talktime"),rs.getInt("smscount"),rs.getDouble("price"));
                }else if(id==2){
                    servicePackage=new NetPackage(id,rs.getString("packagename"),rs.getInt("flow"),rs.getDouble("price"));
                }else if(id==3){
                    servicePackage=new SuperPackage(id,rs.getString("packagename"),rs.getInt("talktime"),rs.getInt("smscount"),rs.getInt("flow"),rs.getDouble("price"));
                }
            }
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            try{
                if(rs!=null){
                    rs.close();
                }
            }catch (SQLException e) {
                e.printStackTrace();
            }
        }
        return servicePackage;

    }
}
